package org.jsola.hr.helper;

import org.jsola.hr.constant.EmpInfoRequireType;
import org.jsola.hr.constant.EmpInfoScene;
import org.jsola.hr.dto.EmpTrainRequireAddDTO;
import org.jsola.hr.dto.EmpTrainRequireUpdateDTO;
import org.jsola.hr.entity.EmpTrainRequireDO;
import org.jsola.hr.query.EmpTrainRequireQuery;
import org.jsola.hr.service.IEmpTrainRequireService;
import org.jsola.hr.vo.EmpTrainRequireVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class EmpTrainRequireTestHelper extends BaseTestHelper {

    @Autowired
    private IEmpTrainRequireService empTrainRequireService;

    /**
     * 生成add测试数据
     * @return EmpTrainRequireAddDTO
     */
    public EmpTrainRequireAddDTO getEmpTrainRequireAddDTO(){
        EmpTrainRequireAddDTO empTrainRequireAddDTO = new EmpTrainRequireAddDTO();
        empTrainRequireAddDTO.setCompanyId(getRandomValue("varchar",32));
        empTrainRequireAddDTO.setRequireType(EmpInfoScene.ENTRY.getValue());
        empTrainRequireAddDTO.setTrainCourse(EmpInfoRequireType.NO_NEED.getValue());
        empTrainRequireAddDTO.setStartTime(EmpInfoRequireType.NO_NEED.getValue());
        empTrainRequireAddDTO.setEndTime(EmpInfoRequireType.NO_NEED.getValue());
        empTrainRequireAddDTO.setTrainDuration(EmpInfoRequireType.NO_NEED.getValue());
        empTrainRequireAddDTO.setTrainOrgName(EmpInfoRequireType.NO_NEED.getValue());
        empTrainRequireAddDTO.setAssessResult(EmpInfoRequireType.NO_NEED.getValue());
        empTrainRequireAddDTO.setTrainAddress(EmpInfoRequireType.NO_NEED.getValue());
        empTrainRequireAddDTO.setTrainMode(EmpInfoRequireType.NO_NEED.getValue());
        return empTrainRequireAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpTrainRequireUpdateDTO
     */
    public EmpTrainRequireUpdateDTO getEmpTrainRequireUpdateDTO(EmpTrainRequireVO empTrainRequireVO){
        return empTrainRequireService.selectDOById(empTrainRequireVO.getId(), SITE_ID).to(EmpTrainRequireUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpTrainRequireQuery
     */
    public EmpTrainRequireQuery getEmpTrainRequireQuery() {
        EmpTrainRequireQuery empTrainRequireQuery = new EmpTrainRequireQuery();
        List<EmpTrainRequireDO> empTrainRequireDOList = empTrainRequireService.list(new EmpTrainRequireDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empTrainRequireDOList)) {
            EmpTrainRequireDO empTrainRequireDO = empTrainRequireDOList.get(0);
            empTrainRequireQuery = empTrainRequireDO.to(EmpTrainRequireQuery.class);
        }
        return empTrainRequireQuery;
    }

    /**
     * 保存示例
     * @return EmpTrainRequireVO
     */
    public EmpTrainRequireVO saveEmpTrainRequireExample(){
        EmpTrainRequireAddDTO addDTO = this.getEmpTrainRequireAddDTO();
        EmpTrainRequireVO empTrainRequireVO = empTrainRequireService.save(addDTO,buildTokenUser());
        return empTrainRequireVO;
    }


}

